from DataStructor.stack import Stack


def divideBy2(dec_number):
	rem_stack = Stack()

	while dec_number > 0:
		rem = dec_number % 2
		rem_stack.push(rem)
		dec_number = dec_number // 2

	binString = ""
	while not rem_stack.is_empty():
		binString = binString + str(rem_stack.pop())

	return binString


def base_converter(dec_number, base):
	"""
	将十进制转换成任意进制数
	:param dec_number: 十进制数
	:param base: 基数2/8/10/16(进制)
	:return: 对应的进制表达字符串
	"""
	digits = "0123456789ABCDEF"
	rem_stack = Stack()

	while dec_number > 0:
		rem = dec_number % base
		rem_stack.push(rem)
		dec_number = dec_number // base

	new_string = ""
	while not rem_stack.is_empty():
		new_string = new_string + digits[rem_stack.pop()]
	return new_string


if __name__ == '__main__':
	print(divideBy2(789))
	print("100的16进制是{}".format(base_converter(100, 16)))
